package com.whut.customer.util;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.shiro.crypto.hash.SimpleHash;

public class MD5Util {
    public static String md5(String src) {
        return DigestUtils.md5Hex(src);
    }

    private static final String salt = "1a2b3c4d";

    public static String inputPassToFormPass(String inputPass) {
        String str = "" + salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(5) + salt.charAt(4);
        return md5(str);
    }

    public static String formPassToDBPass(String formPass, String saltDB) {
        String str = "" + saltDB.charAt(0) + saltDB.charAt(2) + formPass + saltDB.charAt(5) + saltDB.charAt(4);
        return md5(str);
    }

    public static String inputPassToDbPass(String input,String saltDB) {
        String formPass = inputPassToFormPass(input);
        String dbPass = formPassToDBPass(formPass, saltDB);
        return dbPass;
    }

    public static String getDbPassByShiro(String inputPwd,String salt){
        String algorithmName = "MD5";//加密算法
        Object source = inputPwd;//要加密的密码
        int hashIterations = 2;//加密次数
        SimpleHash simpleHash = new SimpleHash(algorithmName,inputPwd,salt,hashIterations);
        return simpleHash.toString();
    }

    public static void main(String[] args) {
        System.out.println(inputPassToDbPass("qwe123","33TCvX")); // 7e23a725b2aa32cd3891cb51a5a3cbf1
        System.out.println(inputPassToDbPass("qwe123","LlnVQi")); // 992e0246754a6d7d43bd169337de95e2
        System.out.println(getDbPassByShiro("123456","fzf1a2b3c4d"));
        System.out.println(getDbPassByShiro("123456","lostkL3a28"));
        System.out.println(getDbPassByShiro("123456","lostDirtqmuhwq"));
        System.out.println(getDbPassByShiro("123456","qwePrSiyH"));

    }

}
